package org.zfes.snowier.cloud.zbss.loan.loan.controller;

import java.util.Map;
import java.util.Optional;

import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.annos.RepeatToken;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.cloud.zbss.loan.loan.model.LoanVisitInfo;
import org.zfes.snowier.cloud.zbss.loan.loan.service.ILoanVisitInfoService;
@Controller 
@RequestMapping("/loan/loanVisitInfo")
public class LoanVisitInfoController extends BaseController {

	
	@Autowired
	private ILoanVisitInfoService loanVisitInfoService;
	
	//@RequiresPermissions(value="loanVisitInfo:loadLoanVisitInfoDataSet",desc="访问信息列表")
    @RequestMapping(value="/loadLoanVisitInfoDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadLoanVisitInfoDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  loanVisitInfoService.loadLoanVisitInfoDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	//@RequiresPermissions(value="loanVisitInfo:createLoanVisitInfo",desc="访问信息添加")
	@RepeatToken
    @RequestMapping(value="/createLoanVisitInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createLoanVisitInfo(LoanVisitInfo loanVisitInfo){
		loanVisitInfoService.createLoanVisitInfo(loanVisitInfo);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="loanVisitInfo:loadLoanVisitInfo",desc="访问信息加载")
    @RequestMapping(value="/loadLoanVisitInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadLoanVisitInfo(Long id){
		Optional<LoanVisitInfo> ops = loanVisitInfoService.loadLoanVisitInfoById(id);
		return ajaxQuery("loanVisitInfo",ops);
    }
	
	//@RequiresPermissions(value="loanVisitInfo:updateLoanVisitInfo",desc="访问信息更新")
    @RequestMapping(value="/updateLoanVisitInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateLoanVisitInfo(LoanVisitInfo loanVisitInfo){
		loanVisitInfoService.updateLoanVisitInfo(loanVisitInfo);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="loanVisitInfo:deletLoanVisitInfo",desc="访问信息删除")
    @RequestMapping(value="/deleteLoanVisitInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteLoanVisitInfo(Long id){
		loanVisitInfoService.deleteLoanVisitInfo(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

	@RequestMapping(value="/selectCount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object selectCount(){
		JSONObject obj = new JSONObject();
		Long sumVisit = loanVisitInfoService.sumVisitCount();
		Long todayVisit = loanVisitInfoService.todayVisitCount();
		obj.put("sumVisit",sumVisit);
		obj.put("todayVisit",todayVisit);
		return obj;
	}

}